﻿using System;
using System.IO;
// using Framework.Misc;
using Unity.VisualScripting;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace Editor.Extension.UI
{
    /*
    [CustomEditor(typeof(SoundPlay))]
    public class SoundPlayEditor : UnityEditor.Editor
    {
        private SerializedProperty _audioClipProp;
        private SerializedProperty _audioPathProp;
        private AudioClip _previousAudioClipRef; // 移动到这里，作为编辑器脚本中的变量
        private bool _guiChanged;

        private void OnEnable()
        {
            _guiChanged = false;
            _audioClipProp = serializedObject.FindProperty("audioClip");
            _audioPathProp = serializedObject.FindProperty("audioPath");

            var targetScript = (SoundPlay)target;
            _previousAudioClipRef = targetScript.audioClip;

            // UpdateAudioFilePath(targetScript);
        }

        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            EditorGUILayout.BeginVertical();
            
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Audio Clip", GUILayout.Width(120));
            EditorGUILayout.PropertyField(_audioClipProp, GUIContent.none, true);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Audio Path", GUILayout.Width(120));
            // 置灰，不可编辑
            EditorGUI.BeginDisabledGroup(true);
            EditorGUILayout.TextField(_audioPathProp.stringValue);
            EditorGUI.EndDisabledGroup();
            EditorGUILayout.EndHorizontal();
            
            EditorGUILayout.EndVertical();
            
            // 检测音频剪辑引用变化并更新音频文件路径
            if (((SoundPlay)target).audioClip != _previousAudioClipRef)
            {
                _previousAudioClipRef = ((SoundPlay)target).audioClip;
                UpdateAudioFilePath((SoundPlay)target);

                _guiChanged = true;
            }
            
            // 必须在此处应用更改，以确保音频文件路径实时更新
            serializedObject.ApplyModifiedProperties();
            
            if (_guiChanged)
            {
                _guiChanged = false;
                AssetDatabase.SaveAssets();
            }
        }

        // 更新音频文件路径的方法
        private void UpdateAudioFilePath(SoundPlay player)
        {
            _audioPathProp.stringValue = player.audioClip != null 
                ? AssetDatabase.GetAssetPath(player.audioClip) 
                : "";
        }
    }
    */
}